package com.java.grammer.arrays;

import java.util.Scanner;

public class Array_Test3 {
    public static void main(String[] args) {
        int[] a = new int[]{2, 3, 5, 6, 35, 24, 1, 2};
        Array1 p1 = new Array1();
        int b = p1.getMax(a);
        System.out.println("这个数组的最大值为：" + b);
        //数组翻转
        p1.reverse(a);
        //数组打印
        p1.print(a);
        //数组查找
        p1.serch(a);
        int[] p = new int[]{12, 4, 24, 532, 5325};

    }
}

class Array1 {
    //获取最大值
    public int getMax(int[] a) {
        int max = 0;
        for (int i = 0; i < a.length; i++) {
            if (a[i] > max) {
                max = a[i];
            }
        }
        return max;
    }

    //数组的反转
    public void reverse(int[] a) {
        for (int i = 0; i < a.length / 2; i++) {
            int t = a[a.length - 1 - i];
            a[a.length - 1 - i] = a[i];
            a[i] = t;
        }
    }

    //打印数组
    public void print(int[] a) {
        for (int i = 0; i < a.length; i++) {
            System.out.print(a[i] + " ");
        }
        System.out.println();
    }

    //数组的查找
    public void serch(int[] a) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入你要找的数");
        int b = sc.nextInt();
        for (int i = 0; i < a.length; i++) {
            if (a[i] == b) {
                System.out.println("找到了，这个数的索引值为：" + i);
                break;
            } else if (i == a.length - 1) {
                System.out.println("没找到");
                break;
            }
        }
    }
}

